package logic

import (
	"context"
	"yktwo/yktworpc/yktworpc"

	"yktwo/api/internal/svc"
	"yktwo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductAddLogic) ProductAdd(req *types.ProductAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	ProductAdd, err := l.svcCtx.YKTwoRpc.ProductAdd(l.ctx, &yktworpc.ProductAddRequest{
		ProduceCode: req.ProduceCode,
		Img:         req.Img,
		ProduceName: req.ProduceName,
		Price:       float32(req.Price),
		Store:       int64(req.Store),
		Status:      int64(req.Status),
		UserId:      int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    "200",
		Data:    ProductAdd,
	}, nil

}
